#include "fontpainter.h"

FontPainter::FontPainter()
{
    // font settings
#if defined(Q_OS_MAC)
    this->_font = QFont("Arial", 12);
    this->_font.setStyleStrategy(QFont::NoAntialias);

    this->_font = QFont("Arial", 10);
    this->_font.setStyleStrategy(QFont::NoAntialias);

    this->_italicFont = QFont("Arial", 12, QFont::StyleItalic);
    this->_italicFont.setStyleStrategy(QFont::NoAntialias);

    this->_boldFont = QFont("Arial Bold", 12, QFont::Black);
    this->_boldFont.setStyleStrategy(QFont::NoAntialias);
#else
    this->_font = QFont("Arial", 10);
    this->_font.setStyleStrategy(QFont::NoAntialias);

    this->_font = QFont("Arial", 8);
    this->_font.setStyleStrategy(QFont::NoAntialias);

    this->_italicFont = QFont("Arial", 10, QFont::StyleItalic);
    this->_italicFont.setStyleStrategy(QFont::NoAntialias);

    this->_boldFont = QFont("Arial", 10, QFont::Bold);
    this->_boldFont.setStyleStrategy(QFont::NoAntialias);
#endif

    this->_fontMetrics = new QFontMetricsF(this->_font);
    this->_boldFontMetrics = new QFontMetricsF(this->_boldFont);
    this->_italicFontMetrics = new QFontMetricsF(this->_italicFont);
}

QFont FontPainter::font()
{
    return this->_font;
}

QFont FontPainter::smallFont()
{
    return this->_smallFont;
}

QFont FontPainter::italicFont()
{
    return this->_italicFont;
}

QFont FontPainter::boldFont()
{
    return this->_boldFont;
}

FontPainter::~FontPainter()
{
    qDebug("deleting fontPainter");
    delete this->_fontMetrics;
    delete this->_boldFontMetrics;
    delete this->_italicFontMetrics;
}

qreal FontPainter::stringWidth(QString text)
{
    qreal width = this->_fontMetrics->width(text);

    return ceil(width);
}

qreal FontPainter::boldStringWidth(QString text)
{
    qreal width = this->_boldFontMetrics->width(text);

    return ceil(width);
}

qreal FontPainter::italicStringWidth(QString text)
{
    qreal width = this->_italicFontMetrics->width(text);

    return ceil(width);
}

qreal FontPainter::stringHeight()
{
    return ceil(this->_fontMetrics->height());
}

qreal FontPainter::boldStringHeight()
{
    return ceil(this->_boldFontMetrics->height());
}

qreal FontPainter::italicStringHeight()
{
    return ceil(this->_italicFontMetrics->height());
}

QRect FontPainter::textRect(QString text)
{
    return QRect(QPoint(0, 0), QSize(this->stringWidth(text), this->stringHeight()));
}

QRect FontPainter::boldTextRect(QString text)
{
    return QRect(QPoint(0, 0), QSize(this->boldStringWidth(text), this->boldStringHeight()));
}

QRect FontPainter::italicTextRect(QString text)
{
    return QRect(QPoint(0, 0), QSize(this->italicStringWidth(text), this->italicStringHeight()));
}
